package regAlloc;

import temp.Temp;
import flowGraph.FlowGraph;
import graph.Node;

public class Liveness extends InterferenceGraph {

        private TempGraph tempGraph = new TempGraph();

        public Liveness(FlowGraph flow) {
                doInterferenceGraph(flow);
        }
        
        public TempGraph getTempGraph() {
                return tempGraph;
        }

        private void doInterferenceGraph(FlowGraph flow) {
    flow.liveness();
    for(Node  n : flow.inn.keySet()) {
       for(Temp temp_aux : flow.inn.get(n)) {
          for(Temp temp_aux2 : flow.inn.get(n)) {
             if(temp_aux!=temp_aux2) {
               tempGraph.addEdge(temp_aux, temp_aux2);  // Adcionar aresta entre eles
             }
                            // verificar se ja existe aresta? e ta adicionando no grafo certo?
          }
       }
     }
    
    for(Node  n : flow.out.keySet()) {
        for(Temp temp_aux : flow.out.get(n)) {
           for(Temp temp_aux2 : flow.out.get(n)) {
              if(temp_aux!=temp_aux2) {
                  tempGraph.addEdge(temp_aux, temp_aux2);
              }
                             // verificar se ja existe aresta? e ta adicionando no grafo certo?
           }
        }
      }

        }

        @Override
        public TempNode tnode(Temp temp) {
                return tempGraph.haveNode(temp);
        }

        @Override
        public Temp gtemp(Node node) {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
        public MoveList moves() {
                // TODO Auto-generated method stub
                return null;
        }

}